﻿DELETE FROM ACCOUNT_PLANNING_FX_FO

INSERT INTO ACCOUNT_PLANNING_FX_FO
SELECT LEFT(CONVERT(VARCHAR(8), [DEAL DATE],112),6) AS YEARMONTH ,
		CIF,
		[BASE AMOUNT],
		[TERM AMOUNT] 
		FROM SAOKESPOT
		WHERE [TRẠNG THÁI] = 'THÀNH CÔNG' AND CIF IN (SELECT CIF FROM TBL_ACCOUNT_PLANNING)

INSERT INTO ACCOUNT_PLANNING_FX_FO
SELECT LEFT(CONVERT(VARCHAR(8), [DEAL DATE],112),6) AS YEARMONTH ,
		CIF,
		[BASE AMOUNT],
		[TERM AMOUNT] 
		FROM SaoKeForward
		WHERE [TRẠNG THÁI] = 'THÀNH CÔNG' AND CIF IN (SELECT CIF FROM TBL_ACCOUNT_PLANNING)


		select min([DEAL DATE]), max([DEAL DATE]) from saokespot